<?php


namespace App\Http\Middleware;


use App\Http\Common\BaseController;
use Closure;
use Illuminate\Support\Facades\Redis;

class LoginOperate extends BaseController
{
    public function handle($request, Closure $next){
        //获取token
        $token = $request->header("Authorization");

        //获取登录后的信息
        $value = json_decode(Redis::get($token));

        if (!$value) return $this->returnJson(BaseController::NOT_LOGGED_IN, '请登录后在访问');

        $request->userId = $value->id;

        return $next($request);
    }
}
